package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.Manifest;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.ImageUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.stark.cartoonavatarmaker.lib.core.AvatarRole;
import com.stark.cartoonavatarmaker.lib.core.AvatarRoleDbUtil;
import com.stark.cartoonavatarmaker.lib.core.AvatarUtil;

import flc.ast.BaseAc;
import flc.ast.HomeActivity;
import flc.ast.R;
import flc.ast.databinding.ActivityPreviewBinding;
import io.reactivex.rxjava3.core.ObservableEmitter;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.utils.FileP2pUtil;
import stark.common.basic.utils.RxUtil;
import stark.common.basic.utils.StkPermissionHelper;

public class PreviewActivity extends BaseAc<ActivityPreviewBinding> {

    public static String imgPath;


    @Override
    protected int onCreate() {
        return R.layout.activity_preview;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);

        mDataBinding.ivPreviewBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.tvPreviewSave.setOnClickListener(this);

        Glide.with(mContext).load(imgPath).into(mDataBinding.ivPreviewImg);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.tvPreviewSave://保存
                save();
                break;
        }
    }

    @Override
    protected void initData() {

    }

    private void save() {
        showDialog(getString(com.stark.common.res.R.string.saving));
        RxUtil.create(new RxUtil.Callback<Boolean>() {
            @Override
            public void doBackground(ObservableEmitter<Boolean> emitter) {
                ImageUtils.save2Album(ImageUtils.view2Bitmap(mDataBinding.ivPreviewImg), Bitmap.CompressFormat.PNG);
                emitter.onNext(true);
            }

            @Override
            public void accept(Boolean save) {
                ToastUtils.showShort(getString(R.string.save_success));
                dismissDialog();
                startActivity(HomeActivity.class);
            }
        });
    }

}